﻿using Marqdown.PostProcessing;
using NUnit.Framework;

namespace MarkdownSharpTests
{
    /// Upgrading HierarchicalStrings to add a close method to properly manage trailing ']' chars.
    [TestFixture]
    class TestHierarchicalStrings
    {
        [Test]
        public void TestSingleChar()
        {
            var s = new HierarchicalString();
            s.add('a');
            Assert.AreEqual("[a", s.ToString());
        }
        [Test]
        public void TestSingleCharClose()
        {
            var s = new HierarchicalString();
            s.add('a');
            s.close();
            Assert.AreEqual("[a]", s.ToString());
        }
        [Test]
        public void TestTwoChars()
        {
            var s = new HierarchicalString();
            s.add('a');
            s.add('b');
            Assert.AreEqual("[ab", s.ToString());
        }
        [Test]
        public void TestTwoCharsClose()
        {
            var s = new HierarchicalString();
            s.add('a');
            s.add('b');
            s.close();
            Assert.AreEqual("[ab]", s.ToString());
        }
        [Test]
        public void TestStringPlusNestedString()
        {
            var s = new HierarchicalString();
            s.add("ab");
            var t = s.addNestedString();
            t.add("cd");
            Assert.AreEqual("[ab[cd", s.ToString());
        }
        [Test]
        public void TestStringPlusNestedStringClose()
        {
            var s = new HierarchicalString();
            s.add("ab");
            var t = s.addNestedString();
            t.add("cd");
            t.close();
            Assert.AreEqual("[ab[cd]", s.ToString());
        }
        [Test]
        public void TestStringPlusNestedPlusString()
        {
            var s = new HierarchicalString();
            s.add("ab");
            var t = s.addNestedString();
            t.add("cd");
            t.close();
            s.add("ef");
            Assert.AreEqual("[ab[cd]ef", s.ToString());
        }
        [Test]
        public void TestStringPlusNestedPlusStringClose()
        {
            var s = new HierarchicalString();
            s.add("ab");
            var t = s.addNestedString();
            t.add("cd");
            t.close();
            s.add("ef");
            s.close();
            Assert.AreEqual("[ab[cd]ef]", s.ToString());
        }
        [Test]
        public void TestStringPlusNestedInlinePlusStringClose()
        {
            var s = new HierarchicalString();
            s.add("ab");
            var t = s.addNestedInline();
            t.add("cd");
            t.close();
            s.add("ef");
            s.close();
            Assert.AreEqual("[ab(cd)ef]", s.ToString());
        }
    }
}
